package com.fengquan.slicing.util;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.request.async.DeferredResult;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @ClassName SwaggerConfig
 * @Description: swagger配置
 * @Author Feng Quan
 * @Date 2020/5/9
 * @Version V1.0
 **/
@Configuration
@EnableSwagger2
public class SwaggerConfig {
    /**
     * 方法1：直接扫描包名路径
     * 方法2：在Application启动类@SpringBootApplication注解加 scanBasePackages = "com.young"
     * @return
     */
    @Bean
    public Docket api(){
        Docket docket = new Docket(DocumentationType.SWAGGER_2).
                groupName("接口API").
                genericModelSubstitutes(DeferredResult.class).
                useDefaultResponseMessages(false).
                forCodeGeneration(true).
                select().
              apis(RequestHandlerSelectors.basePackage("com.fengquan.slicing")).
        //apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)).
                        build().
                        apiInfo(apiInfo());
        return docket;
    }
    private ApiInfo apiInfo() {
        ApiInfo apiInfo = new ApiInfo("本地测试",//大标题
                "",//小标题
                "1.0",//版本
                "没有服务条款",
                new Contact("Feng Quan", "", "fengquanboy@163.com"),//作者
                "霸气小青年",//链接显示文字
                "https://www.cnblogs.com/fengquan-blog/"//网站链接
        );
        return apiInfo;
    }
}
